<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
/**
 * Created by PhpStorm.
 * Keyword: Administrator
 * Date: 2020/3/14
 * Time: 17:18
 */
namespace app\lnadmin\controller;
use app\core\InitController;
use think\facade\View;
use app\lnadmin\model\admin\Keyword as KeywordModel;

class Keyword extends InitController
{

    // 列表
    public function list()
    {
        return View::fetch('keyword');
    }
   //列表详情
    public function index_json($limit='15')
    {
        $param = $this->request->param();
        $ensitive = new KeywordModel();
        if (isset($param['subscribe'])) {
            $ensitive = $ensitive->whereLike('word','%'.$param['subscribe'].'%');
        }
        $list = $ensitive->order('id asc')->paginate($limit);
        $this->result($list);
    }
    // 数据
    public function infoinfo()
    {   
        $get = $this->request->get();
        $data = KeywordModel::lists($get);
        return $this->success($data['data'], $data['count']);
    }

    // 新增
    public function add()
    {      
        if ($this->request->isPost()) {
            $param = $this->request->param(); 
        if (!$param['word']) return false;
        unset($param['id']);
        $param['type'] = KeywordModel::TYPE_WORD;  
        $res = KeywordModel::add($param);
        add_admin_log('add', '关键词');// 记录行为日志
         return $res ? $this->success(true,0,'新增成功') : $this->error('新增失败');
    }
            return $this->fetch('saveKeyword');
  }
    // 编辑
    public function edit()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param(); 
        $edit = KeywordModel::update($param, ['id'=>$param['id']]);
        add_admin_log('edit', '关键词');// 记录行为日志
        return $edit ? $this->saveSuccess() : $this->error();
    }
          
        return $this->fetch('saveKeyword', ['data' => KeywordModel::where('id', input('id'))->find()]);
    }

    // 删除
    public function del()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            KeywordModel::destroy($param['id'],true);
        }
        add_admin_log('del', '关键词');// 记录行为日志
        return $this->success(true, 0, '删除成功');
    }
    // 全部启用 // 全部禁用
    public function statuslog()
    {
        if ($this->request->isPost()) {
            $uid = $this->request->get('uid');
            if($uid==0){
                KeywordModel::where(['status'=>1])->update(['status'=>$uid]);
            }else{
                KeywordModel::where(['status'=>0])->update(['status'=>$uid]);
            }
         return $this->success(true, 0, '操作成功');
       }
    }

}